package xyz.heyaoshare.core.controller.system.menu;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import xyz.heyaoshare.annotation.OperationLog;
import xyz.heyaoshare.common.entity.bo.Result;
import xyz.heyaoshare.core.controller.system.menu.vo.req.*;
import xyz.heyaoshare.core.controller.system.menu.vo.resp.MenuDetailRespVO;
import xyz.heyaoshare.core.controller.system.menu.vo.resp.MenuTreeRespVO;
import xyz.heyaoshare.core.service.system.MenuService;

import java.util.List;

import static xyz.heyaoshare.common.constants.VersionManager.V001;

/**
 * 菜单相关
 * @author YueHe
 * @version 0.0.1
 * @since 2025/5/9 下午4:25
 */
@RestController
@RequestMapping(V001 + "/system/menu")
@Tag(name = "菜单相关")
public class MenuController {

    @Resource
    private MenuService menuService;

    @OperationLog
    @GetMapping("tree/list")
    @Operation(summary = "菜单树列表", description = "查询所有正常的菜单列表，用于前端页面显示所有菜单管理")
    public Result<List<MenuTreeRespVO>> selectList(@ParameterObject @Valid MenuListReqVO reqVO) {
        List<MenuTreeRespVO> items = menuService.selectTreeList(reqVO);
        return Result.ok(items);
    }

    @OperationLog
    @GetMapping
    @Operation(summary = "菜单详情")
    public Result<MenuDetailRespVO> selectDetail(@ParameterObject @Valid MenuDetailReqVO reqVO) {
        MenuDetailRespVO item = menuService.selectDetail(reqVO);
        return Result.ok(item);
    }

    @OperationLog
    @PostMapping("insert")
    @Operation(summary = "新增菜单")
    public Result<Boolean> insert(@RequestBody @Valid MenuInsertReqVO reqVO) {
        Boolean status = menuService.insert(reqVO);
        return Result.ok(status);
    }

    @OperationLog
    @DeleteMapping("delete")
    @Operation(summary = "删除菜单")
    public Result<Boolean> delete(@RequestBody @Valid MenuDeleteReqVO reqVO) {
        Boolean status = menuService.delete(reqVO);
        return Result.ok(status);
    }

    @OperationLog
    @PutMapping("update")
    @Operation(summary = "更新菜单")
    public Result<Boolean> updateData(@RequestBody @Valid MenuUpdateReqVO reqVO) {
        Boolean status = menuService.updateData(reqVO);
        return Result.ok(status);
    }

}